package com.devteam.weatherforcecast;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Toast;

public class SplashScreen extends Activity {
	LinearLayout backGround;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash_screen);
			handler.sendEmptyMessageDelayed(0, 2000);
	}

	Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			Animation anim = AnimationUtils.loadAnimation(
					getApplicationContext(), R.anim.scaleanpha);
			ProgressBar p = (ProgressBar) findViewById(R.id.progressBar1);
			p.startAnimation(anim);
			if(checkNetworkAvailable(getBaseContext())==0){
			startActivity(new Intent(SplashScreen.this, WeatherForecastActivity.class));
			}
			if(checkNetworkAvailable(getBaseContext())==1){
				Toast.makeText(getBaseContext(), "CHỜ KẾT NỐI INTERNET", Toast.LENGTH_LONG).show();	
			}
			finish();
		};
	};
	
	public static int checkNetworkAvailable(Context c) {
		// get connection manager from system service
		ConnectivityManager manager = (ConnectivityManager) c
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		// get network info status
		NetworkInfo netInfo = manager.getActiveNetworkInfo();
		// check availability status
		if (netInfo != null && netInfo.isAvailable()
				&& netInfo.isConnectedOrConnecting()) {
			return 1;
		}
		 
			return 0;
	}
}